{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'request_id': '1679823249,7bf9d8ca-bd6b-473b-b35a-7550415f4b26', 'time_used': 1467, 'faces': [{'face_token': '0b8e431a837d37c14e39276b4ea051ec', 'face_rectangle': {'top': 142, 'left': 603, 'width': 291, 'height': 291}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 20}, 'emotion': {'anger': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.0, 'neutral': 100.0, 'sadness': 0.0, 'surprise': 0.0}, 'beauty': {'male_score': 79.327, 'female_score': 80.282}}}], 'image_id': 'hafUvj6D5A2lcwxPhLU7Zg==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('F:\\API、机器学习与人工智能\\易烊千玺图片.jfif', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"api_key\":\"sNbG6PksVPBaCxrbY0Il3jRnvWl2f5KQ\",\n",
    "         \"api_secret\":\"bX2UXJ5veQqpG6jl3FjfMup_rmEIxMIj\",\n",
    "         \"image_base64\":img,\n",
    "         \"return_attributes\":\"gender,age,emotion,beauty\"\n",
    "         }\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'request_id': '1679823302,ca23c6f4-c37c-421e-a9d2-25f5e4296e9b', 'time_used': 133, 'faces': [{'face_token': 'f11df327e59872c892d3dda3a124bcab', 'face_rectangle': {'top': 142, 'left': 603, 'width': 291, 'height': 291}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 20}, 'emotion': {'anger': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.0, 'neutral': 100.0, 'sadness': 0.0, 'surprise': 0.0}, 'beauty': {'male_score': 79.327, 'female_score': 80.282}}}], 'image_id': 'hafUvj6D5A2lcwxPhLU7Zg==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('F:\\API、机器学习与人工智能\\易烊千玺图片.jfif', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"api_key\":\"sNbG6PksVPBaCxrbY0Il3jRnvWl2f5KQ\",\n",
    "         \"api_secret\":\"bX2UXJ5veQqpG6jl3FjfMup_rmEIxMIj\",\n",
    "         \"image_base64\":img,\n",
    "         \"return_attributes\":\"gender,age,emotion,beauty\"\n",
    "         }\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
